﻿using AutoMapper;
using B.S.Traceability.Domain;
using B.S.Traceability.Error;
using B.S.Traceability.Infrastructure.Interface;
using B.S.Traceability.Read.API.Application.Commends.Health;
using MediatR;

namespace B.S.Traceability.Read.API.Application.CommendHandlers.Health
{
    public class GetHealthCommendHandlers : IRequestHandler<GetHealthCommends, APIResult<List<Healths>>>
    {

        private readonly IBaseRepository<Healths> healthsRepository;
        private readonly IMapper mapper;

        public GetHealthCommendHandlers(IBaseRepository<Healths> healthsRepository, IMapper mapper)
        {
            this.healthsRepository = healthsRepository;
            this.mapper = mapper;
        }


        /// <summary>
        /// 显示保健信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<List<Healths>>> Handle(GetHealthCommends request, CancellationToken cancellationToken)
        {
            APIResult<List<Healths>> result = new APIResult<List<Healths>>();

            result.Code = APIEnum.查询成功;
            result.Msg = "查询成功";
            var list = healthsRepository.GetAll().Where(p => p.BatchId == request.BatchId && p.IsDel == false);
            result.data = list.ToList();
            return await Task.FromResult(result);
        }
    }
}
